package org.example;

import org.apache.flink.api.common.functions.FlatMapFunction;
import org.apache.flink.api.common.typeinfo.Types;
import org.apache.flink.api.java.functions.KeySelector;
import org.apache.flink.api.java.tuple.Tuple2;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.util.Collector;

/*
 * @Description: dataStream有界流,lambda表达式，泛型擦除，显示指定返回类型
 */
public class WordCountStreamUnDemo {
    public static void main(String[] args) throws Exception {
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
        env.setParallelism(1);
        env.readTextFile("input/1.txt").flatMap((String value, Collector<Tuple2<String, Integer>> out) -> {
            for (String s : value.split(" ")) {
                out.collect(Tuple2.of(s,1));
            }
        }).returns(Types.TUPLE(Types.STRING,Types.INT)).keyBy(0)
        .sum(1).print();
        env.execute();
    }
}
